package net.fdukedom.epicurus.domain.entity;

public final class AccessRule {

    /**
     * Action id.
     */
    private int id;
    
    /**
     * Group.
     */
    private Group group;
    
    /**
     * Action.
     */
    private Action action;
    
    /**
     * Plugin.
     */
    private Plugin plugin;
    
    /**
     * AccessType.
     */
    private int accessType;
    
    /**
     * Execution right.
     */
    public static int EXECUTE = 0x01;

    /**
     * @return the accessType
     */
    public int getAccessType() {
        return accessType;
    }

    public AccessRule() {
    }

    /**
     * Creates instance out of all needed parameters.
     *
     * @param group group for which access rule is created.
     * @param action action for which access rule is created.
     * @param plugin parent plug-in
     * @param accessType access type
     */
    public AccessRule(Group group, Action action, Plugin plugin, int accessType) {
        this.accessType = accessType;
        setGroup(group);
        setPlugin(plugin);
        setAction(action);
    }

    /**
     * @param access the accessType to set
     */
    public void setAccessType(int access) {
        this.accessType = access;
    }

    /**
     * @return the action
     */
    public Action getAction() {
        return action;
    }

    /**
     * @param action the action to set
     */
    public void setAction(Action action) {
        this.action = action;
    }

    /**
     * @return the group
     */
    public Group getGroup() {
        return group;
    }

    /**
     * @param group the group to set
     */
    public void setGroup(Group group) {
        this.group = group;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the plugin
     */
    public Plugin getPlugin() {
        return plugin;
    }

    /**
     * @param plugin the plugin to set
     */
    public void setPlugin(Plugin plugin) {
        this.plugin = plugin;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final AccessRule that = (AccessRule) o;

        if (accessType != that.accessType) return false;
        if (action != null ? !action.equals(that.action) : that.action != null) return false;
        if (group != null ? !group.equals(that.group) : that.group != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (group != null ? group.hashCode() : 0);
        result = 29 * result + (action != null ? action.hashCode() : 0);
        result = 29 * result + accessType;
        return result;
    }
}
